package com.g3.zoosite.service.impl;

import com.g3.zoosite.model.DwWatchGuide;
import com.g3.zoosite.mapper.DwWatchGuideMapper;
import com.g3.zoosite.service.IDwWatchGuideService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 动物观赏指南表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-09-28
 */
@Service
public class DwWatchGuideServiceImpl extends ServiceImpl<DwWatchGuideMapper, DwWatchGuide> implements IDwWatchGuideService {

    @Autowired(required = false)
    DwWatchGuideMapper dwWatchGuideMapper;

    //图片服务器地址
    @Value("${image-server}")
    private String imageServer;

    /**
     * 查询所有动物观赏指南业务逻辑层方法
     */
    @Override
    public List<DwWatchGuide> loadAnimals() {
        List<DwWatchGuide> animals = dwWatchGuideMapper.selectList(null);
        for (int i=0; i<animals.size();i++){
            DwWatchGuide dwWatchGuide = animals.get(i);
            //拼接图片服务器地址和图片路径
            dwWatchGuide.setImagePath(imageServer + dwWatchGuide.getImagePath());
        }
        return animals;
    }

    /**
     * 按id查询动物观赏指南业务逻辑层方法
     */
    @Override
    public DwWatchGuide loadAnimal(Integer id) {
        DwWatchGuide animal = dwWatchGuideMapper.selectById(id);
        //拼接图片服务器地址和图片路径
        animal.setImagePath(imageServer+animal.getImagePath());
        return animal;
    }
}
